<template>
  <div class="wrap">
    <van-field v-model="tel" type="number" placeholder="请输入手机号" label="手机号" />
    <van-field
      v-model="sms"
      label="短信验证码"
      placeholder="请输入短信验证码"
    >
      <template #button>
        <van-button size="small" type="primary" color="#000" @click="getCode"
          >发送验证码</van-button
        >
      </template>
    </van-field>
    <button class="loginBtn" @click="getUpdateAppUserPayPassword">确认设置</button>
  </div>
</template>

<script>
import { Field, Button } from "vant";
import { apiForgetAppUserPayPassword,getCodeReq } from "@/request/api"; // api接口
export default {
  name: "App",
  data() {
    return {
      tel: "",
      sms: "",
      passWord: this.$route.query.passWord, //更改密码 上一页填写的密码信息
    };
  },
  mounted() {
    console.log('passWord',this.passWord)
    document.querySelector("body").setAttribute("style", "background-color:#F2F4FA");
  },
  methods: {
    //获取短信验证码:
    getCode() {
     getCodeReq({
        type: 3,
        mobile: this.tel,
      }).then((res) => {
        if(res.code==200){
          this.$toast.success('发送成功，请注意查收')
        }
        console.log("getCodeReq", res);
      });
    },
     //找回支付密码：
    getUpdateAppUserPayPassword() {
        if(!this.tel||!this.sms){
            this.$toast.fail('请检查手机号或验证码是否正确')
            return
        }
      apiForgetAppUserPayPassword({
          checkCode:Number(this.sms),
          mobile:Number(this.tel),
          newPassword:Number(this.passWord),
      }).then((res) => {
         if(res.code==200){
            this.$toast.success('设置成功!')
            this.$router.push({
              path: "/pages/bMyWallet",
              query: {
                //传递参数
              },
            });
          }
      });
    },
  },
  created() {},
  components: {
    [Field.name]: Field,
    [Button.name]: Button,
  },
};
</script>

<style scoped>
.wrap {
  /* margin-top: 30px; */
}
.loginBtn {
  width: 90%;
  margin: 20px auto;
  margin-left: 5%;
  background-color: #000;
  color: #fff;
  font-size: 16px;
  height: 50px;
  /* line-height: 50px; */
  border: 0px;
  border-radius: 20px;
  text-align: center;
}
</style>
